<%--
  Created by IntelliJ IDEA.
  User: litao
  Date: 2020/2/9
  Time: 5:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.bootcss.com/weui/1.1.3/style/weui.min.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/jquery-weui/1.2.1/css/jquery-weui.min.css">
</head>
<body>



<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">account</label></div>
        <div class="weui-cell__bd">
            <input id="input_account" class="weui-input" type="text" placeholder="请输入账号">
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label">nickname</label></div>
        <div class="weui-cell__bd">
            <input id="input_nickname"  class="weui-input" type="text" placeholder="请输入昵称">
        </div>
    </div>
</div>
<%--<input type="button" id="me" value="ajaxGet测试" onclick="getCourse()"/>--%>
<%--<input type="button" id="post" value="ajaxPost测试" onclick="postCourse()"/>--%>

<a href="javascript:;" class="weui-btn weui-btn_primary" onclick="register()">注册</a>


<script src="https://cdn.bootcss.com/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/jquery-weui.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/swiper.min.js"></script>
<script src="https://cdn.bootcss.com/jquery-weui/1.2.1/js/city-picker.min.js"></script>

<script>
    function register() {
        var inputAccount=$("#input_account").val();
        var input_nickname=$("#input_nickname").val();
        var jsonData=JSON.stringify({id:123,account:inputAccount,nickname:input_nickname});
        postCourse(jsonData);
        $.alert("注册成功");
    }

    function postCourse(_data) {
        $.ajax({
            url: '/postone',
            type: 'post',
            dataType: 'json',
            data: _data,
            contentType: "application/json",
            async: false,
            timeout: 50000,
            success: function (data) {
                console.log(data);
            },
            error: function (msg) {
                var errorMsg = '无法获取课程';
                console.log(msg);
            }
        });
    }

    //get请求，参数放在URL后面和data里面都是一样的
    function getCourse() {
        $.ajax({
            // url: '/queryone?id=12',
            url: '/queryone',
            type: 'GET',
            dataType: 'json',
            data: {id: 26},
            async: false,
            timeout: 50000,
            success: function (data) {
                document.getElementById('course').innerHTML = data;
                console.log(data);
            },
            error: function (msg) {
                var errorMsg = '无法获取课程';
                document.getElementById('course').innerHTML = errorMsg;
                console.log(msg);
            }
        });
    }
</script>

<
/body>
< /html>
